/*
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.io.Serializable;
import java.lang.reflect.Method;

public class CglibProxy {
    public static void main(String[] args) {
        //目标对象
        Singer target = new Singer();
        //代理对象
        Singer proxy = (Singer) new ProxyFactory(target).getProxyInstance();
        System.out.println(proxy.toString());
        Singer.print();
        //执行代理对象的方法
        proxy.sing();
    }

}

class ProxyFactory implements MethodInterceptor {
    // 维护目标对象
    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    // 给目标对象创建一个代理对象
    public Object getProxyInstance() {
        //1.工具类
        Enhancer en = new Enhancer();
        //2.设置父类
        en.setSuperclass(target.getClass());
        //3.设置回调函数
        en.setCallback(this);
        //4.创建子类(代理对象)
        return en.create();
    }

    */
/**
     * 目标对象的所有方法都会进入里面，所有方法都会被增强
     *//*

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println(method.getName());
        System.out.println("向观众问好"); //标黄
        //执行目标对象的方法
//        Object returnValue = method.invoke(target, args);
        Object returnValue = proxy.invokeSuper(obj, args);
        System.out.println("谢谢大家"); //标黄
        return returnValue;
    }
}*/
